2020-2021 Sunseeker Telemetry and Lighting System
usci_a_spi_ex1_slave.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 #include "driverlib.h"
33 
34 //*****************************************************************************
73 //
74 //*****************************************************************************
75 
76 uint8_t transmitData = 0x01, receiveData = 0x00;
78 
79 void main (void)
80 {
81  //Stop watchdog timer
82  WDT_A_hold(WDT_A_BASE);
83 
84  //If clock signal from master stays low, it is not yet in SPI mode
85  while ( GPIO_INPUT_PIN_LOW ==
86  GPIO_getInputPinValue(
87  GPIO_PORT_P3,
88  GPIO_PIN0
89  )) ;
90 
91  //P3.5,4,0 option select
92  GPIO_setAsPeripheralModuleFunctionInputPin(
93  GPIO_PORT_P3,
94  GPIO_PIN0 + GPIO_PIN4 + GPIO_PIN5
95  );
96 
97  //Initialize slave to MSB first, inactive high clock polarity and 3 wire SPI
98  returnValue = USCI_A_SPI_initSlave(USCI_A0_BASE,
99  USCI_A_SPI_MSB_FIRST,
100  USCI_A_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT,
101  USCI_A_SPI_CLOCKPOLARITY_INACTIVITY_HIGH
102  );
103 
104  if (STATUS_FAIL == returnValue){
105  return;
106  }
107 
108  //Enable SPI Module
109  USCI_A_SPI_enable(USCI_A0_BASE);
110 
111  //Enable Receive interrupt
112  USCI_A_SPI_clearInterrupt(USCI_A0_BASE,
113  USCI_A_SPI_RECEIVE_INTERRUPT
114  );
115  USCI_A_SPI_enableInterrupt(USCI_A0_BASE,
116  USCI_A_SPI_RECEIVE_INTERRUPT
117  );
118 
119  //Enter LPM4, enable interrupts
120  __bis_SR_register(LPM4_bits + GIE);
121 }
122 
123 //******************************************************************************
124 //
125 //This is the USCI_B0 interrupt vector service routine.
126 //
127 //******************************************************************************
128 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
129 #pragma vector=USCI_A0_VECTOR
130 __interrupt
131 #elif defined(__GNUC__)
132 __attribute__((interrupt(USCI_A0_VECTOR)))
133 #endif
134 void USCI_A0_ISR (void)
135 {
136  switch (__even_in_range(UCA0IV,4)){
137  //Vector 2 - RXIFG
138  case 2:
139  //USCI_A0 TX buffer ready?
140  while (!USCI_A_SPI_getInterruptStatus(USCI_A0_BASE,
141  USCI_A_SPI_TRANSMIT_INTERRUPT
142  )) ;
143 
144  //Transmit data to master
145  USCI_A_SPI_transmitData(USCI_A0_BASE,
147  );
148 
149  //Receive data from master
150  receiveData = USCI_A_SPI_receiveData(USCI_A0_BASE);
151 
152  //Increment data to be transmitted
153  transmitData++;
154 
155  break;
156 
157  default: break;
158  }
159 }
160 
#define STATUS_FAIL
Definition: hw_memmap.h:23
uint8_t receiveData
void main(void)
void USCI_A0_ISR(void)
uint8_t transmitData
uint8_t returnValue